﻿using System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using XiAnAirport.BUS;
using XiAnAirport.Models;

namespace XiAnAirport.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class OrganizationController : ControllerBase
    {
        public IHttpContextAccessor _contextAccessor;
        private JwtSettings _jwtSettings;
        public OrganizationController(IHttpContextAccessor contextAccessor, IOptions<JwtSettings> jwtSettingsAccesser)
        {
            _contextAccessor = contextAccessor;
            _jwtSettings = jwtSettingsAccesser.Value;
        }

        /// <summary>
        /// 查询机构
        /// </summary>
        /// <param name="organizationInfo">组织信息</param>
        /// 
        /// <returns>success</returns>
        [HttpPost]
        [Route("QueryOrganizationList")]
        public ResponseMessage QueryOrganizationList(OrganizationInfo organizationInfo)
        {
            ResponseMessage message = new ResponseMessage();
            OrganizationBUS BUS = new OrganizationBUS();
            try
            {
                message = BUS.QueryOrganization(organizationInfo);
            }
            catch (Exception e)
            {
                message.errcode = 3;
                message.errmsg = "查询机构异常";
                message.data = null;
                message.total = 0;
                LogHelper.Log(e.ToString());
                LogBUS logBUS = new LogBUS();
                ErrorLogInfo errorLogInfo = new ErrorLogInfo();
                errorLogInfo.operation = "查询机构";
                errorLogInfo.errorMsg = e.ToString();
                logBUS.InsertErrorLog(errorLogInfo);
            }
            return message;
        }
    }
}
